package com.huage_06.lesson_02;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionTest {
    public static void main(String[] args) {
        //1.创建集合对象
        Collection<Student> std = new ArrayList<Student>();
        //2.创建存储元素
        Student std1 = new Student();
        std1.setName("张三");
        std1.setAge(23);
        Student std2 = new Student("李四",24);
        Student std3 = new Student("王五",25);

        //3.存储元素
        std.add(std1);
        std.add(std2);
        std.add(std3);

        //4.遍历集合中元素
        Iterator<Student> it = std.iterator();
        while (it.hasNext()){
            Student s = it.next();
            System.out.println(s.getName()+","+s.getAge());
        }
    }
}
